home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
matrix.arc
/
M_MULTIP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1985-01-13
|
4KB
|
30 lines
static char *sccsid = "@(#)m_multiply.c 4/6/82 (U of Maryland, FLB)";
#include "mat.h"
struct matrix *
m_multiply(mat1, mat2)
register struct matrix *mat1, *mat2;
{
register struct matrix *result;
register int row, col, ix;
double sum;
if (mat1->m_cols != mat2->m_rows) {
printf("m_multiply: matrices not compatible.\n");
return(M_NULL);
}
m_create(result, mat1->m_rows, mat2->m_cols);
for (row = 0; row < mat1->m_rows; row++)
for (col = 0; col < mat2->m_cols; col++) {
sum = 0.0;
for (ix = 0; ix < mat1->m_cols; ix++)
sum += m_v(mat1, row, ix) * m_v(mat2, ix, col);
m_v(result, row, col) = sum;
}
return(result);
}